/**
* @author attilax 1466519819@qq.com
* @version  c0
* Copyright 2013 attilax reserved.
* All content (including but not limited to text, pictures, etc.) have copyright restrictions, the note license.
* all the software source code  copyright belongs to the original owner.
* Creative Commons protocol use please follow the "sign for non-commercial use consistent"; we do not welcome the large-scale duplication, and all rights reserved.
* Commercial sites or unauthorized media may not copy software source code.
**/
 
 


 
package com.mijie.homi.search.service.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mijie.homi.common.constant.MCKey;
import com.mijie.homi.common.domain.user.User;
import com.mijie.homi.search.dao.user.MoodUserDao;
import com.mijie.homi.search.dao.user.UserDao;
import com.mijie.homi.search.domain.user.MoodUser;
import com.mijie.homi.search.service.MemcacheService;

@Service
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
public class UserService {

	@Autowired
	private UserDao dao;
	@Autowired
	private MoodUserDao moodUserDao;
	@Autowired
	private MemcacheService mcs;
	
	@Transactional(rollbackFor={Exception.class})
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
	public int decrNumOfRelatedTopic(int id){
		int succ = dao.decrNumOfRelatedTopic(id);
		if(succ>0){
			mcs.delete(MCKey.USER_EXTINFO_BY_ID, String.valueOf(id));
		}
		return succ;
	}
	
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
	public User getUserById(int id){
		User user = (User) mcs.get(MCKey.USER_BY_ID, String.valueOf(id));
		if(user==null){
			user = dao.getUserById(id);
			if(user!=null) mcs.set(MCKey.USER_BY_ID, String.valueOf(id), MCKey.USER_CACHE_TIMEOUT, user);
		}
		return  user;
	}
	
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
	public List<MoodUser> listRecentlyLoginMoodUser(String atleastLastLoginAt,int offset,int limit){
		return moodUserDao.listRecentlyLoginMoodUser(atleastLastLoginAt,offset, limit);
	}
	
}